package com.itheima.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.entity.QueryPageBean;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional //事务
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;

    @Override
    public void addCheckItem(CheckItem checkItem) {
        checkItemMapper.addCheckItem(checkItem);
    }

    @Override
    public Map findPageCheckItem(QueryPageBean queryPageBean) {
        //使用分页插件,注入页码和页面数据数
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());

        //按照搜索条件查询页面数据
        List<CheckItem> checkItemList = checkItemMapper.findPageCheckItem(queryPageBean.getQueryString());

        //注入进分页插件
        PageInfo<CheckItem> pageInfo = new PageInfo<CheckItem>(checkItemList);

        //创建Map
        Map map=new HashMap();
        //存储页面数据
        map.put("checkItemList",pageInfo.getList());
        //存储总条数
        map.put("total",pageInfo.getTotal());

        return map;
    }

    @Override
    public void deleteCheckItemById(Integer id) {
        checkItemMapper.deleteCheckItemById(id);
    }

    @Override
    public void updateCheckItem(CheckItem checkItem) {
        checkItemMapper.updateCheckItem(checkItem);
    }

    @Override
    public List<CheckItem> findAllCheckItem() {
        return checkItemMapper.findAllCheckItem();
    }
}
